//
//  UIButton+button.m
//  App
//
//  Created by huanchi on 15/9/29.
//  Copyright © 2015年  上海欢炽网络科技有限公司. All rights reserved.
//

#import "UIButton+Property.h"

@implementation UIButton (Property)

-(void)buttonWithTitle:(NSString *)title color:(UIColor *)color font:(UIFont *)font{
    [self buttonWithTitle:title color:color font:font bgColor:SY_COLOR_CLEAR];
}

-(void)buttonWithTitle:(NSString *)title color:(UIColor *)color font:(UIFont *)font bgColor:(UIColor*)bgColor{
    [self setTitle:title forState:UIControlStateNormal];
    [self setTitleColor:color forState:UIControlStateNormal];
    [self.titleLabel setFont:font];
    self.backgroundColor = bgColor;
}

-(void)buttonWithTitle:(NSString *)title color:(UIColor *)color normalColor:(UIColor *)normal selectedColor:(UIColor *)select font:(UIFont *)font{
    [self buttonWithTitle:title color:color selectedColor:color normalColor:normal selectedColor:select font:font];
}

-(void)buttonWithTitle:(NSString *)title color:(UIColor *)color selectedColor:(UIColor *)selected normalColor:(UIColor *)normal selectedColor:(UIColor *)select font:(UIFont *)font{
    UIImage *image = [UIImage imageWithColor:normal size:self.bounds.size];
    UIImage *image2 = [UIImage imageWithColor:select size:self.bounds.size];
    [self buttonWithTitle:title color:color selectedColor:selected normalImage:image selectedImage:image2 font:font];
}

-(void)buttonWithTitle:(NSString *)title color:(UIColor *)color normalImage:(UIImage *)normal selectedImage:(UIImage *)select font:(UIFont *)font{
    [self buttonWithTitle:title color:color selectedColor:color normalImage:normal selectedImage:select font:font];
}

-(void)buttonWithTitle:(NSString *)title color:(UIColor *)color selectedColor:(UIColor *)selected normalImage:(UIImage *)normal selectedImage:(UIImage *)select font:(UIFont *)font{
    [self buttonWithTitle:title color:color font:font];
    [self setTitleColor:selected forState:UIControlStateHighlighted];
    [self setTitleEdgeInsets:UIEdgeInsetsMake(0, -self.bounds.size.width, 0, 0)];
    [self setImage:normal forState:UIControlStateNormal];
    [self setImage:select forState:UIControlStateHighlighted];
    [self setShowsTouchWhenHighlighted:YES];
}

-(void)cutLayerCorner{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:self.bounds.size];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = self.bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}
@end

@implementation UIButton (Operation)

- (void (^)())operation{
    return objc_getAssociatedObject(self, "operation");
}

-(void)setOperation:(void (^)())operation{
    [self addTarget:self action:@selector(clickBtnOperationAction:) forControlEvents:UIControlEventTouchUpInside];
    objc_setAssociatedObject(self, "operation", operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(IBAction)clickBtnOperationAction:(id)sender{
    self.operation();
}
@end

